import lombok.AllArgsConstructor;
import lombok.SneakyThrows;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

@AllArgsConstructor
public class SendThread extends Thread {
 
    private Socket socket;
 
    @SneakyThrows
    @Override
    public void run() {
        // 创建缓冲输入流
        BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
        // 创建打印流，打印到socket的输出流
        PrintStream send=new PrintStream(socket.getOutputStream());
        do {
            // 键盘输入
            String sendMsg =  input.readLine();
            // 输出到打印流
            send.println(sendMsg);
            if("Esc".equals(sendMsg)) break;
        } while (true);
        synchronized (Port.lock) {
            Port.lock.notify();
        }
    }
}